package br.com.poc.pitagorasnumero.view.adapter;

import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;
import br.com.poc.pitagorasnumero.R;
import br.com.poc.pitagorasnumero.view.dto.ResultPitagorasDTO;

/**
 * The Class ExpandableListAdapter.
 * 
 * @author irlan.gomes
 */
public class ExpandableListAdapter extends BaseExpandableListAdapter {

	/** The inflater. */
	private final LayoutInflater inflater;

	/** The asking. */
	private final String asking;

	/** The result. */
	private final String result;

	/**
	 * Instantiates a new expandable list adapter.
	 * 
	 * @param inflater
	 *            the inflater
	 * @param resultDTO
	 *            the result dto
	 */
	public ExpandableListAdapter(final LayoutInflater inflater,
			final ResultPitagorasDTO resultDTO) {
		this.inflater = inflater;
		this.asking = resultDTO.getTypeSignification();
		this.result = resultDTO.getSignificationName();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.ExpandableListAdapter#getGroupView(int, boolean,
	 * android.view.View, android.view.ViewGroup)
	 */
	/** {@inheritDoc} **/
	public View getGroupView(final int groupPosition, final boolean isExpanded,
			View convertView, final ViewGroup parent) {

		convertView = inflater.inflate(R.layout.two_list_item_detail, null);

		final TextView item = (TextView) convertView
				.findViewById(R.id.txt_tipo_resultado);

		item.setTypeface(null, Typeface.BOLD_ITALIC);

		item.setText(asking);

		return convertView;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.ExpandableListAdapter#getChildView(int, int, boolean,
	 * android.view.View, android.view.ViewGroup)
	 */
	/** {@inheritDoc} **/
	public View getChildView(final int groupPosition, final int childPosition,
			final boolean isLastChild, View convertView, final ViewGroup parent) {

		convertView = inflater.inflate(R.layout.two_list_item_detail, null);

		final TextView item = (TextView) convertView
				.findViewById(R.id.txt_resul_pitagoras);

		item.setText(result);

		return convertView;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.ExpandableListAdapter#getChildId(int, int)
	 */
	/** {@inheritDoc} **/
	public long getChildId(final int groupPosition, final int childPosition) {
		return 0;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.ExpandableListAdapter#getGroupId(int)
	 */
	/** {@inheritDoc} **/
	public long getGroupId(final int groupPosition) {
		return 0;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.ExpandableListAdapter#hasStableIds()
	 */
	/** {@inheritDoc} **/
	public boolean hasStableIds() {
		return false;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.ExpandableListAdapter#isChildSelectable(int, int)
	 */
	/** {@inheritDoc} **/
	public boolean isChildSelectable(final int groupPosition,
			final int childPosition) {
		return true;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.ExpandableListAdapter#getChild(int, int)
	 */
	@Override
	public Object getChild(final int groupPosition, final int childPosition) {
		return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.ExpandableListAdapter#getChildrenCount(int)
	 */
	@Override
	public int getChildrenCount(final int groupPosition) {
		return 1;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.ExpandableListAdapter#getGroup(int)
	 */
	@Override
	public Object getGroup(final int groupPosition) {
		return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.ExpandableListAdapter#getGroupCount()
	 */
	@Override
	public int getGroupCount() {
		return 1;
	}
}